package com.cssw.fyzb.core.dao.exchange;

import com.cssw.fyzb.core.model.dodb.GExchangeFDef;
import com.cssw.fyzb.core.model.dodb.YExchangeFDef;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * asa
 * 2020/12/21
 */
@Repository
public class GExchangeFDefDaoImpl implements  GExchangeFDefDao {
    public GExchangeFDef getGExchangeFDef(Long yf_id) {
        return GExchangeFDef.dao.findById(yf_id);
    }
    @Override
    public Page<GExchangeFDef> getAllDef(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * from t_g_exchange_f_def ");
        sqlParse.addSQL(" WHERE state='1'");
        return GExchangeFDef.dao.paginate(page,limit, sqlParse);
    }

    @Override
    public  void delete(Long yfId,Long userId){
        GExchangeFDef gExchangeFDef = new GExchangeFDef();
        gExchangeFDef.setYfId(yfId);
        gExchangeFDef.setUpdateOperId(userId);
        gExchangeFDef.setUpdateTime(new Date());
        gExchangeFDef.setState("0");
        gExchangeFDef.update();
    }

    @Override
    public void update(Long yfId, BigDecimal gCoin, BigDecimal fCoin, Long userId){
        GExchangeFDef gexchangeFDef = new GExchangeFDef();
        gexchangeFDef.setYfId(yfId);
        gexchangeFDef.setUpdateOperId(userId);
        gexchangeFDef.setUpdateTime(new Date());
        gexchangeFDef.setFCoin(fCoin);
        gexchangeFDef.setGCoin(gCoin);
        gexchangeFDef.update();
    }

    @Override
    public void  add( BigDecimal gCoin, BigDecimal fCoin, Long userId){
        GExchangeFDef gexchangeFDef = new GExchangeFDef();
        gexchangeFDef.setCreateOperId(userId);
        gexchangeFDef.setCreateTime(new Date());
        gexchangeFDef.setFCoin(fCoin);
        gexchangeFDef.setGCoin(gCoin);
        gexchangeFDef.setState("1");
        gexchangeFDef.save();
    }

}